local xiantu = fk.CreateSkill{
    name = "wk_heg__xiantu"
}

Fk:loadTranslationTable{
    ["wk_heg__xiantu"] = "献图",
    [":wk_heg__xiantu"] = "其他角色的出牌阶段开始时，你可交给其两张牌，若如此做，此阶段结束时，若其于此回合内杀死过角色，你摸两张牌并失去此技能，否则你失去1点体力。",

    ["#wk_heg__xiantu-give"] = "献图：选择交给 %dest 的两张牌",
    ["#wk_heg__xiantu_trigger"] = "献图",

    ["$wk_heg__xiantu1"] = "将军莫虑，且看此图。",
    ["$wk_heg__xiantu2"] = "我已诚心相献，君何踌躇不前？",
}

xiantu:addEffect(fk.EventPhaseStart,{
    anim_type = "support",
    mute = true,
    can_trigger = function(self, event, target, player, data)
        return target ~= player and player:hasSkill(xiantu.name) and target.phase == Player.Play and not target.dead
      end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local cards = room:askToCards(player,{
            min_num = 2,
            max_num = 2,
            include_equip = true,
            skill_name = xiantu.name,
            prompt = "#wk_heg__xiantu-give::"..target.id,
            cancelable = true,
        })
        if #cards == 2 then 
          event:setCostData(self,{ cards = cards })
          return true
        end
      end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        player:broadcastSkillInvoke(xiantu.name, 1)
        room:doIndicate(player.id, {target.id})
        room:moveCardTo(event:getCostData(self).cards, Player.Hand, target, fk.ReasonGive, xiantu.name, nil, false, player.id)
        room:setPlayerMark(player, "xiantu-phase", 1)
      end,
})

xiantu:addEffect(fk.EventPhaseEnd,{
    mute = true,
    can_trigger = function(self, event, target, player, data)
        return target ~= player and target.phase == Player.Play and player:getMark("xiantu-phase") > 0
      end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if #player.room.logic:getEventsOfScope(GameEvent.Death, 1, function(e)
              local death = e.data
              return death.damage and death.damage.from == target
            end, Player.HistoryPhase) == 0 then
          player:broadcastSkillInvoke("wk_heg__xiantu", 2)
          room:notifySkillInvoked(player, "wk_heg__xiantu", "negative")
          room:loseHp(player, 1, xiantu.name)
        else
          player:broadcastSkillInvoke("wk_heg__xiantu", 1)
          room:notifySkillInvoked(player, "wk_heg__xiantu", "positive")
          player:drawCards(2, xiantu.name)
          room:handleAddLoseSkills(player, "-wk_heg__xiantu", nil)
        end
      end,
})

return xiantu